<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 5/9/14
 * Time: 3:18 PM
 */
class Locations extends Eloquent {

    public static $table = 'locations';
    public static $key = 'id';



    function __construct(){
        parent::__construct();

    }

    public static function parent($pid=0){
        return DB::table('locations')->where('parent_id', '=', $pid);
    }


    public static function child($pid = 0 ){

        $result = DB::table('locations')->where('parent_id', '=', $pid)->take(50);
        if($result){
            return $result;
        }else{
            $pid =  Locations::parent($pid)->parent_id;
            $result = DB::table('locations')->where('parent_id', '=', $pid)->take(50);
            return $result;
        }

    }

}